home *** CD-ROM | disk | FTP | other *** search
- Path: EU.net!sun4nl!xs4all!falstaff
- From: falstaff@xs4all.nl (Falstaff)
- Newsgroups: comp.lang.c
- Subject: Re: routine for yesterday's date
- Date: 31 Mar 1996 08:43:07 GMT
- Organization: XS4ALL, networking for the masses
- Message-ID: <4jlgir$jsf@news.xs4all.nl>
- References: <315c4d0f.19874776@ottnews.shl.com>
- NNTP-Posting-Host: xs1.xs4all.nl
- X-Newsreader: NN version 6.5.0 #666 (NOV)
-
- 75323.455@compuserve.com (Bruce Coghill) writes:
-
- >Greetings,
-
- >In many languages you can specify (reference) a relative date. To
- >find out yesterday's address, In Sybase, for example it is something
- >like dayadd(-1). In dBase you just say "yesterday" in the assignment
- >statement. In my C manual the time.h and time functions are described
- >and how I can pull off each element in the structure (like year,
- >month, day, day-of-the-year), but it isn't clear to me how to subtract
- >a day. In its 19960329 (format yyymmdd), it is easy. But what about
- >19960401? I do have a function that converts a date to julian, but
- >not the other way.
-
- No need to go to julian first. Use something like:
-
- int DIM[12]={31,28,31,30,31,30,31,31,30,31,30,31};
-
- if(!--d)
- {
- if(!--m)
- { m=12;
- y--; }
-
- DIM[1]=(~y&3 && (y%100||!(y%400)))?29:28;
- d=DIM[m-1];
- }
-
- Frank
- --
- The famous GIICM now on line: http://www.xs4all.nl/~falstaff/GIICM.html
- ------------------------------------------------------------------------
- Frank A. Vorstenbosch +31-(70)-355 5241 falstaff@xs4all.nl
-